import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import { API_URL } from '../config';
import UserStore from '../store/User';

@observer class Login extends Component {
    constructor(props) {
        super(props);
        this.state = {
            errorTip: false,
            isLogin: null,
            verifyImgSrc: `${API_URL}/verify/${Date.now()}`
        }
    }
    async componentDidMount() {
        const isLogin = await UserStore.checkLogin();
        this.setState({ isLogin });
        if (isLogin) this.props.history.push('/');
    }
    userLogin = async () => {
        const result = await UserStore.login('15356677386', '123456', '123456');
        if (result.status) {
            this.props.history.push('/');
        }
    };
    userLogin2 = async () => {
        const result = await UserStore.login('xiaoxiao44443', '123456', '123456');
        if (result.status) {
            this.props.history.push('/');
        }
    };
    userLogin3 = async () => {
        const result = await UserStore.login('mrzyd2017', '123456', '123456');
        if (result.status) {
            this.props.history.push('/');
        }
    };
    render() {
        return (
            <div>登录<a href="javascript:void(0);" onClick={this.userLogin}>模拟登录超管</a>-
                <a href="javascript:void(0);" onClick={this.userLogin2}>模拟登录普通管理员</a>-
                <a href="javascript:void(0);" onClick={this.userLogin3}>模拟登录门店超管</a>
            </div>
        );
    }
}

Login.propTypes = {
    history: PropTypes.object
};

export default Login;